#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<queue>

using namespace std;

typedef pair<int, int> PII;

vector<int> minimumTime(int n, vector<vector<int>>& edges, vector<int>& disappear) {
    vector<vector<PII>> adj(n);
    vector<bool> st(n);
    for (auto& edge : edges)
    {
        adj[edge[0]].push_back({ edge[1],edge[2] });
        adj[edge[1]].push_back({ edge[0],edge[2] });
    }

    priority_queue<PII, vector<PII>, greater<PII>> pq;
    pq.push({ 0,0 });
    vector<int> res(n, -1);
    res[0] = 0;
    while (pq.size())
    {
        auto [t, u] = pq.top();
        pq.pop();
        if (st[u])   continue;
        st[u] = true;
        //if(t != res[u])    continue;
        for (auto& [v, length] : adj[u])
        {
            if (t + length < disappear[v] && (res[v] == -1 || t + length < res[v]))
            {
                pq.push({ t + length,v });
                res[v] = t + length;
            }
        }
    }
    return res;
}